package ctrl

/*******************************************************************************
Copyright:cloud
Author:cloudapex@126.com
Version:1.0
Date:2020-06-12
Description: 定时器控制器
*******************************************************************************/
import (
	"gitee.com/cloudapex/ulern/cto"
	"gitee.com/cloudapex/ulern/util"
)

var Timer *timer

func init() { Timer = cto.Install("MC_Timer", &timer{}).(*timer) }

type timer struct {
	cto.ControlBase

	handlers []func(cto.IMTimer)
}

func (this *timer) HandleGore() *cto.Gore {
	return &cto.MCGoreLow
}

func (this *timer) HandleInit() {
	this.ControlBase.HandleInit()

	this.initHandlers()
}
func (this *timer) HandleTerm() {
	this.ControlBase.HandleTerm()
}

// -------- public
func (this *timer) RegistHandler(fun func(m cto.IMTimer)) {
	this.handlers = append(this.handlers, fun)
}

// -------- internal
func (this *timer) initHandlers() {
	util.Log.Infov("Start timer handlers...")

	for _, fun := range this.handlers {
		fun(this)
	}
}
